Skip to content

feat: heuristic 6-stakeholder SWOT analysis replacing mechanical document classification#1155

Merged
pethers merged 47 commits intomainfrom
copilot/enhance-swot-analysis-ai
Mar 16, 2026
Merged

feat: heuristic 6-stakeholder SWOT analysis replacing mechanical document classification#1155
pethers merged 47 commits intomainfrom
copilot/enhance-swot-analysis-ai

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 13, 2026

Replaces the legacy 3-stakeholder document-title-truncation SWOT generator with a heuristic rules-based 6-stakeholder analyzer that produces entries with justification, trend direction, quantitative evidence, cross-references, and confidence scoring.

New: ai-swot-analyzer.ts

  • 6 stakeholder perspectives: Government Coalition, Opposition, EU/International, Private Sector, Civil Society, Citizens/Voters
  • Each SWOT entry includes impact, justification, trendDirection, relatedDocuments, quantitativeEvidence
  • Cross-reference detection between stakeholder entries
  • Confidence scoring per stakeholder analysis
  • STAKEHOLDER_NAMES, STAKEHOLDER_ROLES, CONTEXT_LABELS localized across all 14 languages as Readonly<Record<Language, string>> with English fallbacks

Enhanced renderer (stakeholder-swot-section.ts)

  • Trend indicators (↑↓→) with accessible aria-label fallback when lbl() returns the key itself
  • Expandable justification <details> sections
  • Quantitative evidence badges
  • i18n labels: swotJustification, swotTrendImproving/Stable/Deteriorating, swotEvidence

Generator refactor (generators.ts)

  • Single-pass effectiveType() classification via Map<string, RiksdagenDoc[]> replaces ~9 separate filter() passes
  • EU docs correctly classified as 'fpm' || 'eu' (restoring dual-type handling)
  • Stakeholder name lookups use ?? STAKEHOLDER_NAMES[p].en ?? p defensive fallback
  • Removed duplicate mindmap/Sankey/typeCounts code blocks (merge conflict leftovers)

CSS & i18n

  • New rules in styles/components/swot.css for .swot-trend, .swot-justification, .swot-evidence
  • All 14 language label maps updated
// Single-pass doc classification replaces 9 filter() calls
const classifiedTypes = new Map<string, RiksdagenDoc[]>();
for (const d of docs) {
  const t = effectiveType(d);
  (classifiedTypes.get(t) ?? (classifiedTypes.set(t, []), classifiedTypes.get(t)!)).push(d);
}
const euDocs = [...(classifiedTypes.get('fpm') ?? []), ...(classifiedTypes.get('eu') ?? [])];
Original prompt

This section details on the original issue you should resolve

<issue_title>📊 Enhanced Stakeholder SWOT Analysis with AI-Generated Multi-Perspective Intelligence</issue_title>
<issue_description>## 📋 Issue Type
Feature / Architecture Enhancement

🎯 Objective

Redesign the SWOT analysis generators (swot-section.ts, stakeholder-swot-section.ts) to produce AI-driven, multi-perspective political intelligence instead of document-metadata-derived entries. Expand stakeholder perspectives from 3 to 6+, and ensure all SWOT content is generated through AI reasoning rather than mechanical document classification.

📊 Current State

  • buildDeepInspectionSections() in generators.ts (lines 1102-1253) classifies documents mechanically:
    • Government strengths = propositions + laws + press releases
    • Opposition strengths = committee reports + motions
    • Private sector = hardcoded default strings
  • SWOT entries are document titles truncated to 80 chars (titleOf(d).slice(0, 80))
  • Impact levels (high/medium/low) assigned by document type, not actual policy impact
  • Only 3 stakeholder perspectives: Government, Opposition, Private Sector
  • Fallback strings in SWOT_DEFAULTS are static translations, not contextual analysis
  • stakeholder-swot-section.ts renders data but doesn't analyze it

🚀 Desired State

Expanded Stakeholder Perspectives (6+)

  1. Government Coalition (M, KD, L + SD support) — Policy execution, legislative agenda
  2. Social Democratic Opposition (S, V, C, MP) — Scrutiny, alternative proposals
  3. EU/International Actors — Regulatory alignment, diplomatic implications
  4. Private Sector & Business — Regulatory impact, investment climate
  5. Civil Society & NGOs — Rights impact, democratic accountability
  6. Swedish Citizens/Voters — Service delivery, democratic representation

AI-Generated SWOT Content

Each SWOT entry must be:

  • AI-analyzed: Generated through multi-iteration AI reasoning, not document title extraction
  • Impact-assessed: AI evaluates actual policy impact (high/medium/low) with justification
  • Cross-referenced: Links between related SWOT entries across stakeholders
  • Trend-aware: Incorporates historical context and trend direction
  • Quantified: Includes metrics where available (voting margins, budget figures, poll data)

Architecture Changes

  • Create scripts/data-transformers/content-generators/ai-swot-analyzer.ts:
    interface AISwotAnalysis {
      stakeholder: string;
      perspective: StakeholderPerspective;
      strengths: AISwotEntry[];
      weaknesses: AISwotEntry[];
      opportunities: AISwotEntry[];
      threats: AISwotEntry[];
      crossReferences: SwotCrossReference[];
      confidenceScore: number; // 0-1
    }
    
    interface AISwotEntry {
      text: string;
      impact: 'high' | 'medium' | 'low';
      justification: string;
      relatedDocuments: string[];
      trendDirection: 'improving' | 'stable' | 'deteriorating';
      quantitativeEvidence?: string;
    }
  • Update stakeholder-swot-section.ts to render enhanced SWOT cards with:
    • Trend indicators (↑↓→)
    • Cross-reference links between stakeholder SWOT entries
    • Confidence indicators
    • Expandable justification sections
  • Remove hardcoded SWOT_DEFAULTS from generators.ts

🔧 Implementation Approach

  1. Define StakeholderPerspective type with 6+ perspectives
  2. Create AI analysis prompts for each stakeholder perspective
  3. Implement cross-reference detection between SWOT entries
  4. Add trend analysis using historical document comparison
  5. Update HTML rendering with enhanced SWOT cards
  6. Add CSS for trend indicators, cross-references, and confidence badges
  7. Localize all 6 stakeholder names in 14 languages
  8. Add unit tests for AI SWOT generation

🤖 Recommended Agent

code-quality-engineer — Refactoring SWOT generation from template-based to AI-driven

✅ Acceptance Criteria

  • 6+ stakeholder perspectives (not just 3)
  • All SWOT entries are AI-generated with justification
  • Impact levels based on actual policy analysis, not document type
  • Cross-references between related SWOT entries across stakeholders
  • Trend indicators show direction (improving/stable/deteriorating)
  • Confidence scores on each SWOT analysis
  • No hardcoded SWOT_DEFAULTS fallback strings remain
  • All 14 languages supported with localized stakeholder names
  • WCAG 2.1 AA accessible SWOT cards
  • CSS-only rendering (no JavaScript dependencies)
  • Existing SWOT tests updated or replaced

📚 References

🏷️ Labels

`typ...


💬 Send tasks to Copilot coding agent from Slack and Teams to turn conversations into code. Copilot posts an update in your thread when it's finished.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agentic-workflow Agentic workflow changes ci-cd CI/CD pipeline changes documentation Documentation updates html-css HTML/CSS changes news News articles and content generation refactor Code refactoring size-xl Extra large change (> 1000 lines) testing Test coverage workflow GitHub Actions workflows

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📊 Enhanced Stakeholder SWOT Analysis with AI-Generated Multi-Perspective Intelligence

3 participants